home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 40 / tos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  16.3 KB  |  791 lines

  1. /* An assortment of functions for the Atari with Lattice C compiler.
  2.  *Adapted from a similar set for MSDOS.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include "hack.h"
  7. #include "osbind.h"
  8.  
  9. extern int errno;
  10.     
  11. getuid()
  12. {
  13.     return 1;
  14. }
  15.  
  16. char *
  17. getlogin()
  18. {
  19.     return ((char *) NULL);
  20. }
  21.  
  22. tgetch()
  23. {
  24.     char ch;
  25.     ch = BIOSgetch();
  26.     return ((ch == '\r') ? '\n' : ch);
  27. }
  28.  
  29. #ifdef exit
  30. #undef exit
  31. #endif
  32.  
  33. #undef creat
  34. #define LEVELS    "level.00"
  35. #define BONES    "bones.00"
  36. #define Sprintf (void) sprintf
  37.  
  38. extern char hackdir[], levels[], SAVEF[], bones[], permbones[];
  39. extern int ramdisk;
  40.  
  41. #ifdef SHELL
  42. #include <process.h>
  43. dosh()
  44. {
  45.     char *comspec, *getenv();
  46.     extern char orgdir[];
  47.  
  48.     if (comspec = getenv("COMSPEC")) {
  49.         end_screen();
  50.         clear_screen();
  51.         puts("To return to HACK, type \"exit\" at the DOS prompt.");
  52.         fflush(stdout);
  53.         chdirx(orgdir, 0);
  54.         if (spawnl(P_WAIT, comspec, NULL)) {
  55.             printf("\nCan't execute COMSPEC \"%s\"!\n", comspec);
  56.             flags.toplin = 0;
  57.             more();
  58.         }
  59.         chdirx(hackdir, 0);
  60.         start_screen();
  61.         docrt();
  62.     }
  63.     return(0);
  64. }
  65. #endif SHELL
  66.  
  67. /* Map the keypad to equivalent character output.  If scroll lock is turned
  68.  * on, run without stopping at interesting branches (like YUHJKLBN keys), if
  69.  * it is off, run with stopping at branches (like ^Y^U^H^J^K^L^B^N keys).
  70.  */
  71. static char
  72. BIOSgetch()
  73. {
  74.     int scan,c,result;
  75.     char ch;
  76.     result=Crawcin();
  77.     scan=(result>>16)&0xff;
  78.     c=result&0xff;
  79.     switch (scan) {
  80.         case 0x4a : {/*-*/
  81.             ch=(c==0x2d) ? 'm' : '\20';
  82.             break;
  83.         }
  84.         case 0x4e : {/*+*/
  85.             ch=(c==0x2b) ? 'p' : 'P';
  86.             break;
  87.         }
  88.         case 0x6d : {/*1*/
  89.             ch=(c==0x31) ? 'b' : '\2';
  90.             break;
  91.         }
  92.         case 0x6e : {/*2*/
  93.             ch=(c==0x32) ? 'j' : '\12';
  94.             break;
  95.         }
  96.         case 0x6f : {/*3*/
  97.             ch=(c==0x33) ? 'n' : '\16';
  98.             break;
  99.         }
  100.         case 0x6a : {/*4*/
  101.             ch=(c==0x34) ? 'h' : '\10';
  102.             break;
  103.         }
  104.         case 0x6b : {/*5*/
  105.             ch='.';
  106.             break;
  107.         }
  108.         case 0x6c : {/*6*/
  109.             ch=(c==0x36) ? 'l' : '\14';
  110.             break;
  111.         }
  112.         case 0x67 : {/*7*/
  113.             ch=(c==0x37) ? 'y' : '\31';
  114.             break;
  115.         }
  116.         case 0x68 : {/*8*/
  117.             ch=(c==0x38) ? 'k' : '\13';
  118.             break;
  119.         }
  120.         case 0x69 : {/*9*/
  121.             ch=(c==0x39) ? 'u' : '\25';
  122.             break;
  123.         }
  124.         default : ch=c;
  125.     }
  126.     return (ch);
  127. }
  128.  
  129. dotogglepickup()
  130. {
  131.     flags.pickup = !flags.pickup;
  132.     pline("Pickup: %s.", flags.pickup ? "ON" : "OFF");
  133.     return (0);
  134. }
  135.  
  136. /* from objects.h
  137. char obj_symbols[] = {
  138.     ILLOBJ_SYM, AMULET_SYM, FOOD_SYM, WEAPON_SYM, TOOL_SYM,
  139.     BALL_SYM, CHAIN_SYM, ROCK_SYM, ARMOR_SYM, POTION_SYM, SCROLL_SYM,
  140.     WAND_SYM, RING_SYM, GEM_SYM, 0 };
  141.  */
  142. extern char obj_symbols[];
  143. static char *names[] = {"Illegal objects", "Amulets", "Edibles", "Weapons",
  144.             "Tools", "Iron balls", "Chains", "Rocks", "Armor",
  145.             "Potions", "Scrolls", "Wands", "Rings", "Gems"};
  146. char *
  147. let_to_name(let)
  148. char let;
  149. {
  150.     char *pos = index(obj_symbols, let);
  151.     extern char *HI, *HE;
  152.     /* buffer size is len(HI) + len(HE) + max len(names[]) + 1 */
  153.     static char buf[4 + 4 + 15 + 1];
  154.  
  155.     if (pos == NULL)
  156.         pos = obj_symbols;
  157.     Sprintf(buf, "%s%s%s", HI, names[pos - obj_symbols], HE);
  158.     return (buf);
  159. }
  160.  
  161. /* After changing the value of flags.invlet_constant, make the current
  162.  * inventory letters the fixed ones. -dgk
  163.  */
  164. void
  165. fixinv()
  166. {
  167.     struct obj *otmp;
  168.     extern int lastinvnr;
  169.     char ilet = 'a';
  170.  
  171.     for(otmp = invent; otmp; otmp = otmp->nobj) {
  172.         otmp->invlet = ilet;
  173.         if (++ilet > 'z') ilet = 'A';
  174.     }
  175.     lastinvnr = 51;
  176. }
  177.  
  178. /* construct the string  file.level 
  179.  * This assumes there is space on the end of 'file' to append
  180.  * a two digit number.  This is true for 'bones' and 'level'
  181.  * but be careful if you use it for other things -dgk
  182.  */
  183. void
  184. name_file(file, level)
  185. char *file;
  186. int level;
  187. {
  188.     char *tf;
  189.     
  190.     if (tf = rindex(file, '.'))
  191.         Sprintf(tf+1, "%d", level);
  192. }
  193.  
  194. long
  195. freediskspace(path)
  196. char *path;
  197. {
  198.     int drive = 0;
  199.         struct {
  200.         long freal; /*free allocation units*/
  201.         long total; /*total number of allocation units*/
  202.         long bps;   /*bytes per sector*/
  203.         long pspal; /*physical sectors per allocation unit*/
  204.     } freespace;
  205.     if (path[0] && path[1] == ':')
  206.         drive = (toupper(path[0]) - 'A') + 1;
  207.     if (Dfree(&freespace,drive)<0) return -1;
  208.     return freespace.freal*freespace.bps*freespace.pspal;
  209. }
  210.  
  211. long
  212. filesize(file)
  213. char *file;
  214. {
  215.     long old_dta;
  216.     struct {
  217.         char pad1[21];
  218.         char attr;
  219.         unsigned short time;
  220.         unsigned short date;
  221.         long size;
  222.         char name[14];
  223.     } fcb;
  224.     fcb.size=-1L;
  225.     old_dta=Fgetdta();
  226.     Fsetdta(&fcb);
  227.     Fsfirst(file,0);
  228.     Fsetdta(old_dta);
  229.     return fcb.size;
  230. }
  231.  
  232. long
  233. all_files_size(path)
  234. char *path;
  235. {
  236.     register int level;
  237.     long size, tmp;
  238.     char buf[PATHLEN];
  239.  
  240.     strcpy(buf, path);
  241.     for (level = 1, size = 0; level <= MAXLEVEL; level++) {
  242.         name_file(buf, level);
  243.         tmp = filesize(buf);
  244.         if (tmp > 0)
  245.             size += tmp;
  246.     }
  247.     return (size);
  248. }
  249.  
  250. void
  251. copybones(mode)
  252. int mode;
  253. {
  254.     register int fd, level;
  255.     char from[PATHLEN], to[PATHLEN];
  256.     long sizes[MAXLEVEL + 1];
  257.     extern boolean level_exists[];
  258.     if (!ramdisk)
  259.         return;
  260.     strcpy(to, (mode == TOPERM) ? permbones : bones);
  261.     strcpy(from, (mode == TOPERM) ? bones : permbones);
  262.  
  263.     for (level = 1; level <= MAXLEVEL; level++) {
  264.         name_file(from, level);
  265.         sizes[level] = filesize(from);    /* -1 if file doesn't exist */
  266.         name_file(to, level);
  267.         (void) unlink(to);    /* remove old bones files in 'to' */
  268.     }
  269.     for (level = 1; level <= MAXLEVEL; level++) {
  270.         if (sizes[level] == -1L)
  271.             continue;
  272.         name_file(from, level);
  273.         name_file(to, level);
  274.         if (sizes[level] > freediskspace(to)) {
  275.             fprintf(stderr,
  276.                 "Not enough room to copy file '%s' to '%s'.\n",
  277.                 from, to);
  278.             goto cleanup;
  279.         }
  280.         /* We use savelev and getlev to move the bones files around,
  281.          * but savelev sets level_exists[] TRUE for this level, so
  282.          * we have to set it back FALSE again.
  283.          */
  284. #ifdef TOS
  285.         if ((fd = open(from, 0x8000)) < 0) {
  286. #else TOS
  287.         if ((fd = open(from, 0)) < 0) {
  288. #endif TOS
  289.             fprintf(stderr, "Warning: can't open '%s'.\n", from);
  290.             continue;
  291.         } else {
  292.             sizes[level] = 0;    /* 'from' bones exists */
  293.             getlev(fd, 0, level);
  294.             (void) close(fd);
  295.             if ((fd = creat(to, FMASK)) < 0) {
  296.                 fprintf(stderr,
  297.                     "Warning: can't create '%s'.\n", to);
  298.                 continue;
  299.             } else {
  300.                 savelev(fd, level);
  301.                 (void) close(fd);
  302.                 level_exists[level] = FALSE;    /* see above */
  303.             }
  304.         }
  305.     }
  306.     /* If we are copying bones files back to permanent storage, unlink
  307.      * the bones files in the LEVELS directory.
  308.      */
  309.     if (mode == TOPERM)
  310.         for (level = 1; level <= MAXLEVEL; level++) {
  311.             if (sizes[level] == -1)
  312.                 continue;
  313.             name_file(from, level);
  314.             (void) unlink(from);
  315.         }
  316.     return;
  317.  
  318. cleanup:
  319.     /* Ran out of disk space!  Unlink the "to" files and issue an
  320.      * appropriate message.
  321.      */
  322.     for (level = 1; level <= MAXLEVEL; level++)
  323.         if (sizes[level] == 0) {
  324.             name_file(to, level);
  325.             (void) unlink(to);
  326.         }
  327.     fprintf(stderr, "There is not enough room in ");
  328.     if (mode == TOPERM) {
  329.         fprintf(stderr, "permanent storage for bones files!\n");
  330.         fprintf(stderr,
  331.             "Bones will be left in LEVELS directory '%s'!\n",
  332.             levels[0] ? levels : ".");
  333.             return;
  334.     } else {
  335.         fprintf(stderr,    "LEVELS directory '%s' to copy bones files!\n",
  336.             levels[0] ? levels : ".");
  337.         getreturn("to quit");
  338.         settty("Be seeing you ...\n");
  339.         exit(0);
  340.     }
  341. }
  342.  
  343. saveDiskPrompt(start)
  344. int start;
  345. {
  346.     extern saveprompt;
  347.     char buf[BUFSIZ];
  348.     int i;
  349.  
  350.     if (saveprompt) {
  351.         remember_topl();
  352.         home();
  353.         cl_end();
  354.         printf("If save file is on a SAVE disk, put that disk in now.\n");
  355.         cl_end();
  356.         printf("Name of save file (default: '%s'%s) ? ", SAVEF,
  357.             start ? "" : ", <Esc> aborts save");
  358.         fflush(stdout);
  359.         getlin(buf);
  360.         if (!start && buf[0] == '\033') {
  361.             home();
  362.             cl_end();
  363.             curs(1, 2);
  364.             cl_end();
  365.             return 0;
  366.         }
  367.         for (i = 0; buf[i]; i++)
  368.             if (!isspace(buf[i])) {
  369.                 strncpy(SAVEF, buf, PATHLEN);
  370.                 break;
  371.             }
  372.     }
  373.     return 1;
  374. }
  375.  
  376. /* Prompt for the game disk, then check if you can access the record file.
  377.  * If not, warn the player.
  378.  */
  379. void
  380. gameDiskPrompt()
  381. {
  382.     FILE    *fp;
  383.     extern saveprompt;
  384.  
  385.     if (saveprompt) {
  386.         fputc('\n', stderr);
  387.         getreturn("when the GAME disk is ready");
  388.     }
  389.     if ((fp = fopen(RECORD, "r")))    /* check for GAME disk */
  390.         fclose(fp);
  391.     else {
  392.         fprintf(stderr,
  393.             "\n\nWARNING: I can't find record file '%s'!\n",
  394.              RECORD);
  395.         fprintf(stderr,
  396.             "If the GAME disk is not in, put it in now.\n");
  397.         getreturn("to continue");
  398.     }
  399. }
  400.  
  401. #define CONFIGFILE    "hack103.cnf"
  402. void
  403. read_config_file()
  404. {
  405.     char    config[FILENAME], tmp_ramdisk[PATHLEN], tmp_levels[PATHLEN];
  406.     char    buf[BUFSZ], *bufp;
  407.     FILE    *fp;
  408.     extern    char plname[];
  409.     extern
  410.     int saveprompt;
  411.  
  412.     tmp_ramdisk[0] = 0;
  413.     tmp_levels[0] = 0;
  414.     strcpy(config, hackdir);
  415.     append_slash(config);
  416.     strcat(config, CONFIGFILE);
  417.     if (!(fp = fopen(config, "r"))) {
  418.         fprintf(stderr, "Warning: no configuration file '%s'!\n",
  419.             config);
  420.         getreturn("to continue");
  421.         return;
  422.     }
  423.     while (fgets(buf, BUFSZ, fp)) {
  424.         if (*buf == '#')        /* comment first character */
  425.             continue;
  426.  
  427.         /* remove any trailing whitespace
  428.          */
  429.         bufp = index(buf, '\n');
  430.         while (bufp > buf && isspace(*bufp))
  431.             bufp--;
  432.         if (bufp == buf)
  433.             continue;        /* skip all-blank lines */
  434.         else
  435.             *(bufp + 1) = 0;    /* 0 terminate line */
  436.  
  437.         /* find the '=' separating option name from option value
  438.          */
  439.         if (!(bufp = strchr(buf, '='))) {
  440.             fprintf(stderr, "Bad option line: '%s'\n", buf);
  441.             getreturn("to continue");
  442.             continue;
  443.         }
  444.         
  445.         /* move past whitespace between '=' and option value
  446.          */
  447.         while (isspace(*++bufp))
  448.             ;
  449.  
  450.         /* Now go through the possible configurations
  451.          */
  452.         if (!strncmp(buf, "RAMDISK", 3)) {
  453.             strncpy(tmp_ramdisk, bufp, PATHLEN);
  454.  
  455.         } else if (!strncmp(buf, "LEVELS", 4)) {
  456.             strncpy(tmp_levels, bufp, PATHLEN);
  457.  
  458.         } else if (!strncmp(buf, "OPTIONS", 4)) {
  459.             parseoptions(bufp, TRUE);
  460.             if (plname[0])        /* If a name was given */
  461.                 plnamesuffix();    /* set the character class */
  462.  
  463.         } else if (!strncmp(buf, "SAVE", 4)) {
  464.             char *ptr;
  465.             if (ptr = index(bufp, ';')) {
  466.                 *ptr = '\0';
  467.                 if (*(ptr+1) == 'n' || *(ptr+1) == 'N')
  468.                     saveprompt = FALSE;
  469.             }
  470.             (void) strncpy(SAVEF, bufp, PATHLEN);
  471.             append_slash(SAVEF);
  472.  
  473.         } else if (!strncmp(buf, "GRAPHICS", 4)) {
  474.             int x[9];
  475.             if (sscanf(bufp, "%d%d%d%d%d%d%d%d%d",&x[0],&x[1],
  476.                 &x[2],&x[3],&x[4],&x[5],&x[6],&x[7],&x[8])
  477.                 == 9) {
  478.                 symbol.vwall=(char) x[0];
  479.                 symbol.hwall=(char) x[1];
  480.                 symbol.tlcorn=(char) x[2];
  481.                 symbol.trcorn=(char) x[3];
  482.                 symbol.blcorn=(char) x[4];
  483.                 symbol.brcorn=(char) x[5];
  484.                 symbol.door=(char) x[6];
  485.                 symbol.room=(char) x[7];
  486.                 symbol.corr=(char) x[8];
  487.             }
  488.             else {
  489.                 fprintf(stderr,
  490.                     "GRAPHICS did not contain 9 values\n");
  491.                 getreturn("to continue");
  492.             }
  493.  
  494.         } else if (!strncmp(buf, "DISPLAY", 4)) {
  495.             /* There was a variable called DISPLAY which never
  496.              * work very well and was too confusing.  Leave this
  497.              * code in here for now for 'backward compatibility'.
  498.              */
  499.             ;
  500.  
  501.         } else {
  502.             fprintf(stderr, "Bad option line: '%s'\n", buf);
  503.             getreturn("to continue");
  504.         }
  505.     }
  506.     fclose(fp);
  507.  
  508.     strcpy(permbones, tmp_levels);
  509.     if (tmp_ramdisk[0]) {
  510.         strcpy(levels, tmp_ramdisk);
  511.         if (strcmp(permbones, levels))        /* if not identical */
  512.             ramdisk = TRUE;
  513.     } else
  514.         strcpy(levels, tmp_levels);
  515.     strcpy(bones, levels);
  516. }
  517.  
  518. void
  519. set_lock_and_bones()
  520. {
  521.     if (!ramdisk) {
  522.         strcpy(levels, permbones);
  523.         strcpy(bones, permbones);
  524.     }
  525.     append_slash(bones);
  526.     strcat(bones, BONES);
  527.     append_slash(permbones);
  528.     strcat(permbones, BONES);
  529.     strcpy(lock, levels);
  530.     append_slash(lock);
  531.     strcat(lock, LEVELS);
  532. }
  533.  
  534. void
  535. append_slash(name)
  536. char *name;
  537. {
  538.     char *ptr;
  539.  
  540.     if (!name[0])
  541.         return;
  542.     ptr = name + (strlen(name) - 1);
  543.     if (*ptr != '\\' && *ptr != '/' && *ptr != ':') {
  544.         *(ptr + 1) = '\\';
  545.         *(ptr + 2) = 0;
  546.     }
  547. }
  548.  
  549.  
  550. check_then_creat(file, pmode)
  551. char *file;
  552. int pmode;
  553. {
  554.     long freespace = freediskspace(file);
  555.     extern boolean restoring;
  556.     if (freespace < 0)
  557.         return (-1);
  558.     if (!restoring && freespace < 8000L) {
  559.         pline("â—†HACK is almost out of disk space for making levels!");
  560.         pline("You should save the game now.  Save this game [y/n] ?");
  561.         fflush(stdout);
  562.         if (getchar() == 'y')
  563.             dosave();
  564.         return(-1);    /* In case he decides not to save don't let him
  565.                  * change levels
  566.                  */
  567.     }
  568.     return( creat(file, pmode));
  569. }
  570.  
  571. void
  572. getreturn(str)
  573. char *str;
  574. {
  575.     int ch;
  576.  
  577.     fprintf(stderr, "Hit <RETURN> %s.", str);
  578.     while ((ch = getchar()) != '\n')
  579.         putch(ch);
  580. }
  581.  
  582. void
  583. chdrive(str)
  584. char *str;
  585. {
  586.     int drive;
  587.     char *ptr;
  588.     if ((ptr = index(str, ':')) != NULL) {
  589.         drive = toupper(*(ptr - 1))-'A';
  590.         Dsetdrv(drive);
  591.     }
  592. }
  593.  
  594.  
  595. /* Do a chdir back to the original directory
  596.  */
  597. void msexit(code)
  598. int code;
  599. {
  600. #ifdef CHDIR
  601.     extern char orgdir[];
  602. #endif CHDIR
  603.  
  604. #ifdef DGK
  605.     fflush(stdout);
  606.     copybones(TOPERM);
  607. #endif DGK
  608. #ifdef CHDIR
  609.     Dsetpath(orgdir);    /* do the chdir, but not with chdirx */
  610. #endif CHDIR
  611.     exit(code);
  612. }
  613.  
  614. /*qsort: sort an array.  Really a shell sort, but it will do*/
  615. void qsort(base,nel,size,compar)
  616. char *base;
  617. int nel, size;
  618. int (*compar) ();
  619. {
  620.     int gap, i, j;
  621.     register cnt;
  622.     for (gap=nel>>1; gap>0; gap>>=1)
  623.         for (i=gap; i<nel; i++)
  624.             for (j=i-gap; j>=0; j-=gap) {
  625.                 register char *s1, *s2;
  626.                 s1=base+(j*size);
  627.                 s2=base+((j+gap)*size);
  628.                 if ((*compar)(s1,s2)<=0) break;
  629.                 for (cnt=size;--cnt>=0;) {
  630.                     register char ch;
  631.                     ch=*s1;
  632.                     *s1++=*s2;
  633.                     *s2++=ch;
  634.                 }
  635.             }
  636. /*end qsort*/}
  637.  
  638. static     char *msgs[]={" ",
  639.         "not file owner",
  640.         "no such file or directory",
  641.         "no such process",
  642.         "interrupted system call",
  643.         "I/O error",
  644.         "no such device",
  645.         "argument list too long",
  646.         "exec format error",
  647.         "bad file number",
  648.         "no child process",
  649.         "no more processes allowed",
  650.         "not enough memory space",
  651.         "permission denied",
  652.         "bad memory address",
  653.         "bulk device required",
  654.         "resource is busy",
  655.         "file exists",
  656.         "cross device link",
  657.         "no such device",
  658.         "not a directory",
  659.         "is a directory",
  660.         "invalid argument",
  661.         "no more files allowed",
  662.         "too many open files",
  663.         "not a terminal",
  664.         "text file busy",
  665.         "file too large",
  666.         "no space left on device",
  667.         "illegal seek",
  668.         "read only file system",
  669.         "too many links",
  670.         "broken pipe",
  671.         "math argument error",
  672.         "math result too large"};
  673.  
  674. /*perror: print a string, then the error*/
  675. void perror(s)
  676. char *s;
  677. {
  678.     int select;
  679.     if ((errno<0) || (errno>34)) select=0;
  680.     else select=errno;
  681.     fprintf(stderr,"%s: %s\n",s,msgs[select]);
  682. /*end perror*/}
  683.  
  684. setrandom()
  685. {
  686.     srand(Tgettime());
  687. /*end setrandom*/}
  688.  
  689. getyear()
  690. {
  691.     return (1980+((Tgetdate()>>9)&0x7f));
  692. /*end getyear*/}
  693.  
  694. char *getdate()
  695. {
  696.     static char datestr[7];
  697.     int day, mo, yr, date;
  698.     date=Tgetdate();
  699.     day=date&0x1f;
  700.     mo=(date>>5)&0xf;
  701.     yr=getyear()-1900;
  702.     (void) sprintf(datestr,"%2d%2d%2d",yr,mo,day);
  703.     if (datestr[2]==' ') datestr[2]='0';
  704.     if (datestr[4]==' ') datestr[4]='0';
  705.     return (datestr);
  706. /*getdate*/}
  707. static int cum[]={0,0,31,59,90,120,151,181,212,243,273,304,334};
  708.  
  709. phase_of_the_moon()
  710. {
  711.     int day,mo,epact,golden,date;
  712.     date=Tgetdate();
  713.     day=date&0x1f;
  714.     mo=(date>>5)&0xf;
  715.     day+=cum[mo];
  716.     if (((getyear() % 4)==0) && (mo>2)) day++;
  717.     golden=(getyear()%19)+1;
  718.     epact=(11*golden+18) % 30;
  719.     if ((epact==25 && golden>11) || (epact==24)) epact++;
  720.     return( (((((day+epact)*6)+11)%177)/22)&7);
  721. /*end phase_of_the_moon*/}
  722.  
  723. night()
  724. {
  725.     int hour;
  726.     hour=(Tgettime()>>11)&0x1f;
  727.     return ((hour<6) || (hour>21));
  728. /*end night*/}
  729.  
  730. midnight()
  731. {
  732.     int hour;
  733.     hour=(Tgettime()>>11)&0x1f;
  734.     return (hour==0);
  735. /*end midnight*/}
  736.  
  737. gethdate(name) char *name;
  738. {
  739. /*end gethdate*/}
  740.  
  741. uptodate(fd)
  742. {
  743.     return(1);
  744. /*end uptodate*/}
  745.     
  746. getlock()
  747. {
  748. /*end getlock*/}
  749.  
  750. getenv(s)
  751. char *s;
  752. {
  753.     return(0);
  754. /*end getenv*/}
  755.  
  756. /*getcwd: return the current directory*/
  757. char *getcwd(path,len)
  758. char *path;
  759. int len;
  760. {
  761.     if (Dgetpath(path,0)<0) return (NULL);
  762.     else return(path);
  763. /*end getcwd*/}
  764.  
  765. /*chdir: change directories*/
  766. chdir(path)
  767. char *path;
  768. {
  769.     if (*path) return (Dsetpath(path));
  770.     else return 0;
  771. /*end chdir*/}
  772.  
  773. /*Lattice's strncpy always appends a null*/
  774. int strncpy(to,from,len)
  775. char *to,*from;
  776. int len;
  777. {    int result;
  778.     result=len;
  779.     while (*from && len) {*to++ = *from++; --len;}
  780.     if (len) {*to='\0'; --len;}
  781.     return result-len;
  782. /*end strncpy*/}
  783.  
  784. #ifdef DEBUG
  785. printer(s)
  786. char *s;
  787. {
  788.     while (*s) Cprnout(*s++);
  789. /*end printer*/}
  790. #endif DEBUG
  791.